from langchain_core.documents import Document
import typing as T
from pathlib import Path
from io import BytesIO
from ..document import DocumentLoaderFactory, DocumentSpliterFactory


def loader_spliter(
    blob: T.Union[str, Path, bytes, BytesIO],
    uuid: str,
    file_name: str,
    file_type: str,
    chunk_size: int = 512,
    chunk_overlap: int = 0,
    separators: T.Optional[str] = None,
    **kwargs,
) -> T.List[Document]:
    loader = DocumentLoaderFactory.get_loader(file_type)
    documents = loader.load(blob, uuid, file_name, **kwargs)
    spliter = DocumentSpliterFactory.get_spliter(file_type)
    documents = spliter.spliter(
        documents=documents,
        separators=separators,
        chunk_size=chunk_size,
        chunk_overlap=chunk_overlap,
    )
    return documents
